package com.flyxteam.learner.springboot.endpoint;

import org.springframework.beans.BeansException;
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.flyxteam.learner.springboot.data.SomeData;

// ## 一个自定义的监控端点
@ConfigurationProperties(prefix = "endpoints.some")
public class SomeEndpoint extends AbstractEndpoint<Object> implements ApplicationContextAware {

    // ## 抽象类中没提供无参构造，在此调用父类构造指定该endpoint的id
    public SomeEndpoint() {
        super("some");
    }

    // ## 在此实现端点返回信息
    @Override
    public Object invoke() {
        SomeData someData = applicationContext.getBean(SomeData.class);
        return someData;
    }
    
    ApplicationContext applicationContext;
    
    // ## 注入的ApplicationContext
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
    
}
